#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2e5 + 5;

int n, m;
int f[N];
void init() { rep(i, 1, n) f[i] = i; }
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
bool merge(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx == fy) return false;
  f[fy] = fx;
  return true;
}
struct Edge {
  int id, u, v;
};

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  init();
  vector<Edge> a;
  rep(i, 1, m) {
    int u, v;
    cin >> u >> v;
    if (!merge(u, v)) a.push_back(Edge{i, u, v});
  }
  vector<int> v;
  rep(i, 1, n) if (f[i] == i) v.push_back(i);
  cout << v.size() - 1 << endl;
  while (v.size() > 1) {
    Edge e = a.back();
    a.pop_back();
    int f1 = find(e.u);
    int f2 = v.back();
    v.pop_back();
    if (f1 == f2) {
      cout << e.id << ' ' << e.u << ' ' << v.back() << endl;
      merge(v.back(), f2);
    } else {
      cout << e.id << ' ' << e.u << ' ' << f2 << endl;
      merge(f1, f2);
    }
  }
  return 0;
}